package com.hopes.bizz.risk.transfer.validation;

import com.hopes.bizz.common.core.util.StringUtils;
import com.hopes.bizz.risk.transfer.constant.RiskConstant;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author lyb
 * @version 1.0
 * @date 2024/2/19 14:30
 */
public class WorkTimeValidator implements ConstraintValidator<WorkTime, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        String[] dataArr = value.split(RiskConstant.VALIDATOR_JOIN);
        String checkCycleUnit = dataArr[0];
        if ("小时".equals(checkCycleUnit)) {
            if (dataArr.length != 2) {
                return false;
            }
            String workTime = dataArr[1];
            return StringUtils.isNotBlank(workTime);
        }
        return true;
    }
}
